//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<system_console.h>
///	@path	~/src/lib/system/
///	@date	2007/11/12
///	@desc	Customized system output console.

#pragma once

#include "xeres.h"

#include "config/os.h"

#include "lib/system/lock.h"

#include <vector>

namespace xeres {

	/*!
		\class	SystemConsole
		\brief	Encapsulates system console functions.
	*/
	class SystemConsole
	{
	public:

		/// Console text color.
		enum ConsoleColor
		{
			/// \brief black
			BLACK = 0 ,
			/// \brief red
			RED ,
			/// \brief red + green
			YELLOW ,
			/// \brief green
			GREEN ,
			/// \brief green + blue
			CYAN ,
			/// \brief blue
			BLUE ,
			/// \brief blue + red
			PURPLE ,
			/// \brief red + green + blue
			WHITE ,
			/// \brief 50% white
			GREY ,
			/// \brief red
			DARK_RED ,
			/// \brief red + green
			DARK_YELLOW ,
			/// \brief green
			DARK_GREEN ,
			/// \brief green + blue
			DARK_CYAN ,
			/// \brief blue
			DARK_BLUE ,
			/// \brief blue + red
			DARK_PURPLE ,
			CONSOLE_COLOR_last ,
			/// \brief Current Color
			CURRENT ,
		};

		/// \instance
		static SystemConsole& instance( void );

		/// \name	Console Manipulation
		//@{

		/*!
			\brief		Initialize system console.
		*/
		void Initialize( int width , int height );

		/*!
			\brief		Finalize system console.
		*/
		void Finalize( void );

		/*!
			\brief		Show console.
		*/
		void Show( void );

		/*!
			\brief		Hide console.
		*/
		void Hide( void );

		/*!
			\brief		Show cursor.
		*/
		void ShowCursor( void );

		/*!
			\brief		Hide cursor.
		*/
		void HideCursor( void );

		/*!
			\brief		Set title of console.
		*/
		void SetTitle( const WString& title );

		/*!
			\brief		Set console window proc.
		*/
		void SetProc( WNDPROC proc );

		/*!
			\brief		Print string in x line.
						Notice this function will cut string to fit screen,
						and omit escape character.
		*/
		void PrintLine( int line , int start , const WString& str , ConsoleColor fg = CURRENT , ConsoleColor bg = CURRENT );

		//@}

	private:

		/// \name Constructor & Destructor
		//@{

		/// \ctor
		SystemConsole( void );

		/// \dtor
		~SystemConsole( void );

		//@}

		// data

		// operation lock
		ThreadLock		m_lock;

		// console handle
		HANDLE			m_hConsole;

		// console window
		HWND			m_hWindow;

		// console buffer
		CHAR_INFO *		m_buffer;
		int				m_width , m_height;
	};

} // namespace xeres
